<?php
function getDbConfig()
{
    $res = \think\Db::name('driver_config')->where(['useUser' => 1, 'status' => 1])->select();
    $configArr = [];
    if (!empty($res)) {
        foreach ($res as $k => $v) {
            $configArr[$v['configKey']] = ['name' => $v['configName'], 'value' => $v['configVal']];
        }
    }
    return $configArr;
}

// 获取
function getBaiduCode()
{

}

// 根据经纬度 获取4个点
function getSquares($lat, $lng, $distance = 3)
{
    $dlng = 2 * asin(sin($distance / (2 * 6371)) / cos(deg2rad($lat)));
    $dlng = rad2deg($dlng);
    $dlat = $distance / 6371;
    $dlat = rad2deg($dlat);
    return array('left-top' => array('lat' => $lat + $dlat, 'lng' => $lng - $dlng),
        'right-top' => array('lat' => $lat + $dlat, 'lng' => $lng + $dlng),
        'left-bottom' => array('lat' => $lat - $dlat, 'lng' => $lng - $dlng),
        'right-bottom' => array('lat' => $lat - $dlat, 'lng' => $lng + $dlng)
    );
}
/**
 * oraTreeDataPhp
 * 根据$data数据
 * 生成一个树形数组
 * 递归处理
 * 增加回调函数处理
 * @access public
 * @param array $data 待处理数据
 * @param function $callback 回调函数
 * @param int $parentId 待查询父级id
 * @param string $pid 父级id字段名称
 * @param string $id id字段名称
 * @return array $tree 返回数组
 * @author alexander<gt199899@gmail.com>
 * @version 2014-10-10 下午12:05:28
 * @version 2014-11-24 下午18:16:10
 * @copyright Show More
 */
function getTreeDataPhp($data, $parentId = 0, $pid = 'pid', $id = 'areaId',$callback = ''){
    $tree = array();
    foreach($data as $row){
        if($row[$pid] == $parentId){
            $tmp = getTreeDataPhp($data, $row[$id], $pid, $id);
            if($tmp){
                $row['children'] = $tmp;
            }
           if(!empty($callback)){
               $children['children'] = isset($row['children']) && !empty($row['children']) ? $row['children'] : array();
               $tree[] = !empty($children['children']) ? array_merge(call_user_func($callback, $row), $children) : call_user_func($callback, $row);
           }
            else{
                $tree[] = $row;
            }
        }
    }
    unset($key, $value);
    return $tree;
}

function getcartest(){
    $host = "http://jisuqgclwz.market.alicloudapi.com";
    $path = "/illegal/carorg";
    $method = "GET";
    $appcode = "ea9b09efdaae4d7e8c2e34a6a22db54c";
    $headers = array();
    array_push($headers, "Authorization:APPCODE " . $appcode);
    //发动机号 engineno    220058
    //车架号 frameno    014218
    
    // $querys = "carorg=hangzhou&engineno=".$option['engineno']."&frameno=".$option['frameno']."&iscity=1&lsnum=".$option['lsnum']."&lsprefix=".$option['lsprefix']."&lstype=02&mobile=0";
    $bodys = "";
    $url = $host . $path;

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_FAILONERROR, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HEADER, true);
    if (1 == strpos("$".$host, "https://"))
    {
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    }
    var_dump(curl_exec($curl));
    exit;
}

function getCarorg(){
    // http://api.jisuapi.com/illegal/carorg2?appkey=yourappkey
    $host = "http://api.jisuapi.com/";
    $path = "illegal/carorg2";
    $method = "GET";
    // $appcode = "ea9b09efdaae4d7e8c2e34a6a22db54c";
    $appkey = '7dbcba10a52645b8';
    $headers = array();
    array_push($headers, "Authorization:APPKEY " . $appkey);
    //发动机号 engineno    220058
    //车架号 frameno    014218
    
    // $querys = "carorg=hangzhou&engineno=".$option['engineno']."&frameno=".$option['frameno']."&iscity=1&lsnum=".$option['lsnum']."&lsprefix=".$option['lsprefix']."&lstype=02&mobile=0";
    // $querys = "appkey=".$appcode;
    $bodys = "";
    // $url = $appcode;
    // $url = $host . $path;

    // $url = 'http://jisuqgclwz.market.alicloudapi.com/illegal/carorg2?appkey='.$appcode;
    // echo $url2 = 'http://api.jisuapi.com/illegal/carorg2?appkey='.$appcode;
    // echo '<hr>';
    // echo $url;exit;
    $url = 'http://api.jisuapi.com/illegal/carorg2?appkey='.$appkey;
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_FAILONERROR, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HEADER, false);
    if (1 == strpos("$".$host, "https://"))
    {
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    }
    $result = curl_exec($curl);
        curl_close($curl);
        if($result){
            return $result;
        }else{
            return fasle;
        }
}

function getIllegalInquiry($option){
    $host = "http://jisuqgclwz.market.alicloudapi.com";
    $path = "/illegal/query";
    $method = "GET";
    $appcode = "ea9b09efdaae4d7e8c2e34a6a22db54c";
    $headers = array();
    array_push($headers, "Authorization:APPCODE " . $appcode);
    //发动机号 engineno    220058
    //车架号 frameno    014218
    
    $querys = "carorg=".$option['carorg']."&engineno=".$option['engineno']."&frameno=".$option['frameno']."&iscity=0&lsnum=".$option['lsnum']."&lsprefix=".$option['lsprefix']."&lstype=02";
    // echo $querys;exit;
    $bodys = "";
    $url = $host . $path . "?" . $querys;

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_FAILONERROR, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HEADER, false);
    if (1 == strpos("$".$host, "https://"))
    {
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    }
    $result = curl_exec($curl);
        curl_close($curl);
        if($result){
            return $result;
        }else{
            return false;
        }
}

